<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java Thread: start() vs run() 深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            position: relative;
            overflow: hidden;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 10px;
            right: 15px;
            font-size: 12px;
            color: #666;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        .method-badge {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 500;
            display: inline-block;
            margin-right: 8px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px 30px;
            border-radius: 15px;
            margin: 30px 0;
            position: relative;
            overflow: hidden;
        }
        
        .highlight-box::after {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: pulse 3s ease-in-out infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(0.8); opacity: 0.5; }
            50% { transform: scale(1.2); opacity: 0.8; }
        }
        
        .first-letter {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 20px;
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
        }
        
        pre code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            line-height: 1.6;
        }
        
        .keyword { color: #569cd6; }
        .string { color: #ce9178; }
        .comment { color: #6a9955; }
        .method { color: #dcdcaa; }
        .class { color: #4ec9b0; }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center relative z-10">
            <h1 class="text-5xl md:text-7xl font-bold mb-6 tracking-tight">
                Java Thread 核心解密
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">
                深入理解 start() 与 run() 的本质区别
            </p>
            <div class="flex justify-center space-x-4 text-lg">
                <span class="flex items-center"><i class="fas fa-code mr-2"></i> 并发编程</span>
                <span class="flex items-center"><i class="fas fa-layer-group mr-2"></i> 多线程</span>
                <span class="flex items-center"><i class="fas fa-rocket mr-2"></i> 性能优化</span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="first-letter">T</span>hread 类在 Java 中用于创建和管理线程。<code class="method-badge">start()</code>方法和<code class="method-badge">run()</code>方法是 Thread 类中两个关键的方法，它们在启动和执行线程的过程中发挥着不同的作用。理解这两个方法的区别，是掌握 Java 并发编程的基础。
            </p>
        </div>

        <!-- Visual Diagram -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-project-diagram mr-3 text-purple-600"></i>
                线程执行流程图
            </h2>
            <div class="mermaid">
                graph TD
                    A[创建Thread对象] --> B{调用方法?}
                    B -->|start()| C[创建新线程]
                    B -->|run()| D[当前线程执行]
                    C --> E[线程进入就绪状态]
                    E --> F[JVM调度执行]
                    F --> G[执行run()方法]
                    D --> H[直接执行run()方法]
                    G --> I[线程结束]
                    H --> J[方法返回]
                    
                    style A fill:#f9f,stroke:#333,stroke-width:2px
                    style C fill:#9f9,stroke:#333,stroke-width:2px
                    style D fill:#f99,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- Method Comparison -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <!-- start() Method -->
            <div class="content-card rounded-2xl p-8">
                <div class="feature-icon">
                    <i class="fas fa-play"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">start() 方法</h3>
                <ul class="space-y-4 text-gray-700">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">作用：</strong>启动线程，使线程进入"就绪"状态，并等待 JVM 分配 CPU 时间来执行线程的任务。start() 方法实际上会创建一个新的线程，并在这个线程上调用 run() 方法。
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">执行：</strong>当你调用 start() 方法时，JVM 会为线程分配一个独立的执行路径，线程会在其独立的执行路径中执行 run() 方法中的代码。
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">线程状态：</strong>调用 start() 方法后，线程的状态会变成 RUNNABLE，这意味着它准备好被调度运行。
                        </div>
                    </li>
                </ul>
            </div>

            <!-- run() Method -->
            <div class="content-card rounded-2xl p-8">
                <div class="feature-icon" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
                    <i class="fas fa-code"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">run() 方法</h3>
                <ul class="space-y-4 text-gray-700">
                    <li class="flex items-start">
                        <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">作用：</strong>包含线程的实际任务代码。当线程被启动时，run() 方法中的代码会在新的线程中执行。你不能直接调用 run() 方法来启动一个线程。
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">执行：</strong>如果直接调用 run() 方法，它会在当前线程中执行，而不会创建新的线程。因此，直接调用 run() 方法不会启动新的线程，线程不会并行执行。
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">线程状态：</strong>调用 run() 方法不会改变线程的状态，因为它是在当前线程中执行的。
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <!-- Code Example -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-laptop-code mr-3 text-purple-600"></i>
                示例代码
            </h2>
            <div class="code-block p-6 overflow-x-auto">
                <pre><code><span class="keyword">public class</span> <span class="class">ThreadDemo</span> <span class="keyword">extends</span> <span class="class">Thread</span> {

    <span class="keyword">@Override</span>
    <span class="keyword">public void</span> <span class="method">run</span>() {
        <span class="comment">// 线程执行的任务</span>
        System.out.<span class="method">println</span>(<span class="string">"线程运行中: "</span> + Thread.<span class="method">currentThread</span>().<span class="method">getName</span>());
    }

    <span class="keyword">public static void</span> <span class="method">main</span>(String[] args) {
        <span class="class">ThreadDemo</span> thread1 = <span class="keyword">new</span> <span class="class">ThreadDemo</span>();
        <span class="class">ThreadDemo</span> thread2 = <span class="keyword">new</span> <span class="class">ThreadDemo</span>();

        <span class="comment">// 启动线程</span>
        thread1.<span class="method">start</span>();
        thread2.<span class="method">start</span>();

        <span class="comment">// 直接调用